import 'package:flutter/material.dart';
import 'package:hospitable_rental/pages/home/advisory/index.dart';
import 'package:hospitable_rental/pages/home/home/index.dart';
import 'package:hospitable_rental/pages/home/profile/index.dart';
import 'package:hospitable_rental/pages/home/search/index.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _currentIndex = 0;

  List<Widget> _tabviewList = [
    HomeIndex(),
    SearchIndex(),
    AdvisoryIndex(),
    MineIndex(),
  ];

  List<BottomNavigationBarItem> _items = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: "首页",
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.search_rounded),
      label: "找房",
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.info),
      label: "资讯",
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.person),
      label: "我的",
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _tabviewList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: _items,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.green,
        unselectedItemColor: Colors.green.withOpacity(0.5),
        showUnselectedLabels: true,
        onTap: _onTapItem,
      ),
    );
  }

  void _onTapItem(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}
